package afi;

import static org.junit.Assert.*;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import org.junit.Test;

public class HashingProblemsTest {

	@Test
	public final void testFindAnagramGroups() {

		LinkedList<String> inputList = new LinkedList<String>(Arrays.asList(
				"algorithm", "god", "logarithm", "dog", "snute"));
		LinkedList<List<String>> outputList = new LinkedList<List<String>>();
		outputList.add(new LinkedList<String>(Arrays.asList("algorithm",
				"logarithm")));
		outputList.add(new LinkedList<String>(Arrays.asList("god", "dog")));

		assertEquals(outputList, HashingProblems.findAnagramGroups(inputList));
	}

	@Test
	public final void testTwoSumExists() {

		assertEquals(true,
				HashingProblems.pairSumExists(new int[] { 1, 2, 3, 4 }, 3));
		assertEquals(true,
				HashingProblems.pairSumExists(new int[] { 1, 2, 3, 4 }, 4));
		assertEquals(true,
				HashingProblems.pairSumExists(new int[] { 1, 2, 3, 4 }, 7));

		assertEquals(false,
				HashingProblems.pairSumExists(new int[] { 1, 2, 3, 4 }, 9));
		assertEquals(false,
				HashingProblems.pairSumExists(new int[] { 1, 2, 3, 4 }, -1));
		assertEquals(false, HashingProblems.pairSumExists(new int[] {}, 0));
	}

	@Test
	public final void testCanBeWritten() {

		assertEquals(true, HashingProblems.canBeWritten("hello", "hello"));
		assertEquals(true,
				HashingProblems.canBeWritten("hello", "hello world!"));
		assertEquals(true,
				HashingProblems.canBeWritten("world", "hello world!"));
		assertEquals(true,
				HashingProblems.canBeWritten("ellow", "hello world!"));
		assertEquals(true, HashingProblems.canBeWritten("doho", "hello world!"));

		assertEquals(false, HashingProblems.canBeWritten("hello", ""));
		assertEquals(false, HashingProblems.canBeWritten("hello", "hllo"));
		assertEquals(false, HashingProblems.canBeWritten("hello", "abc"));
	}

	@Test
	public final void testFindHighestClimb() {

		assertEquals(0, HashingProblems.findHighestClimb(new int[] {}));
		assertEquals(0, HashingProblems.findHighestClimb(new int[] { 1 }));
		assertEquals(1, HashingProblems.findHighestClimb(new int[] { 1, 2 }));

		assertEquals(
				7,
				HashingProblems.findHighestClimb(new int[] { 20, 4, 5, 3, 7, 4,
						10 }));
	}

	@Test
	public final void testFindMajority() {

		assertEquals("", HashingProblems.findMajority(new LinkedList<String>()));
		assertEquals("w1", HashingProblems.findMajority(new LinkedList<String>(
				Arrays.asList("w1", "w2", "w1"))));

		assertEquals("w1", HashingProblems.findMajority(new LinkedList<String>(
				Arrays.asList("w1", "w2", "w1"))));
		assertEquals("w1", HashingProblems.findMajority(new LinkedList<String>(
				Arrays.asList("w1", "w2", "w1", "w2", "w1"))));

		assertEquals("w3", HashingProblems.findMajority(new LinkedList<String>(
				Arrays.asList("w1", "w2", "w3", "w3", "w3"))));
	}

	@Test
	public final void testFindFrequent() {

		assertEquals(new LinkedList<String>(),
				HashingProblems.findFrequent(new LinkedList<String>(), 2));

		assertEquals(
				new LinkedList<String>(Arrays.asList("w1")),
				HashingProblems.findFrequent(
						new LinkedList<String>(Arrays.asList("w1", "w2", "w1")),
						2));

		assertEquals(
				new LinkedList<String>(Arrays.asList("w1", "w2")),
				HashingProblems.findFrequent(
						new LinkedList<String>(Arrays.asList("w1", "w2", "w1", "w1", "w2", "w1", "w1", "w2", "w1")),
						3));
	}
}
